package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.entity.Orders;
import com.itheima.service.impl.OrderServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderServiceImpl orderService;
    //用户下单
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        orderService.submit(orders);
        return R.success("下单成功");
    }
    //订单明细
    @GetMapping("/page")
    public R<Page> page(long page, long pageSize, Long number){
        return orderService.OrdersByPages (page, pageSize, number);
    }
    @PutMapping
    public R<String> update(@RequestBody Orders orders){
        orderService.updateStatus (orders);
        return R.success ("派送成功");
    }
    @GetMapping("/userPage")
    public R<Page> OrdersByPages(long page, long pageSize) {
        return orderService.OrdersByPages(page, pageSize);
    }

    @PostMapping("/again")
    public R<String> again(@RequestBody Orders orders) {
        orderService.again(orders);
        return R.success("下单成功");
    }
}
